package com.sxt.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @program: 0812springboot
 * @author: 雷哥
 * @create: 2019-12-18 14:22
 **/
@Configuration
@EnableSwagger2  //启用swagger
public class Swagger2AutoConfiguration {


    @Bean
    public Docket swaggerSpringMvcPlugin() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                   //扫描方法上的@ApiOperation
//                  .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                  .apis(RequestHandlerSelectors.withClassAnnotation(Api.class)) //扫描类上的Api注解的也可以@RestController
//                    .apis(RequestHandlerSelectors.basePackage("com.sxt.controller"))
                  .build();
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().description("这是一个很NB的API工具")
                .contact(new Contact("雷哥", "http://leige.tech", "78414842@qq.com"))  //名片
                .version("1.0")  //版本
                .license("武汉尚学堂")//所有者
                .build();//构造
    }
}
